/**
 * 
 */
package model.student;

import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import myutil.Connect;

import org.apache.struts2.ServletActionContext;

import vo.mixed.HostelStudentVo;

/**
 * @author Sony
 *
 */
public class HostelMo {

	ArrayList<HostelStudentVo> list=new ArrayList<HostelStudentVo>();
	public ArrayList<HostelStudentVo> getHostelDetails() throws Exception {

		HttpSession session;
		session = ServletActionContext.getRequest().getSession();
		int id=(int) session.getAttribute("user_id");
		String query="select rr.description,rr.room_number,cr.residential_name,cr.residential_type,cr.warden_name from residential_room rr,college_residential cr, student_batch sb where sb.room_id=rr.room_id and cr.residential_id=rr.residential_id and student_id="+id;
		System.out.println(query);
		Connect c=new Connect();
		try {
			ResultSet rs=c.getResult(query);
			while(rs.next())
			{
				HostelStudentVo vo=new HostelStudentVo();
				vo.setResidential_name(rs.getString("residential_name"));
				vo.setResidential_type(rs.getString("residential_type"));
				vo.setWarden_name(rs.getString("warden_name"));
				vo.setRoom_number(rs.getInt("room_number"));
				vo.setDescription(rs.getString("description"));
				list.add(vo);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("error in retreiving hostel details");
		}		
		return list;
	}

}
